import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class player here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
//(C)Brice Johnson
public class Player extends Attachable
{
    /**
     * Act - do whatever the player wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    private double mass = 1; 
    public int health = 100;
    
    public int cordX=0;
    public int cordY=0;
    public Location[] locations  = new Location[4];
    boolean init = false;
    
    public Player(){
        super(1, new GreenfootImage("player.png"));
    setImage(new GreenfootImage("player.png"));

    }
    
    public void act() 
    {
        if(!init){
            locations[0] = new Location(getX(),getY(), 90);
            locations[1] = new Location(getX(),getY(), 0);
            locations[2] = new Location(getX(),getY(), 270);
            locations[3] = new Location(getX(),getY(), 180);
            locations[0].setOff(-1,16);
            locations[1].setOff(16,0);
            locations[2].setOff(0,-16);
            locations[3].setOff(-16,-1);
            
    
            addAttatchmentPoint(locations[0]);
            addAttatchmentPoint(locations[1]);
            addAttatchmentPoint(locations[2]);
            addAttatchmentPoint(locations[3]);
            init = true;
        }
        
     for(int x = 0; x < locations.length; x++){
        locations[x].update(getX(),getY());
     }
        
    if(Greenfoot.isKeyDown("w")){
    Play.addMovement(0,.05/mass);
    }
    if(Greenfoot.isKeyDown("s")){
    Play.addMovement(0,-.05/mass);
    }
    if(Greenfoot.isKeyDown("a")){
    Play.addMovement(.05/mass,0);
    }
    if(Greenfoot.isKeyDown("d")){
    Play.addMovement(-.05/mass,0);
    }
     if(Greenfoot.isKeyDown("m")){
        mass += .01;
        }  
    }
    
    public void coordUpdate(double x, double y){
        if(x>0 && x <1){x=1;}
        if(y>0 && y <1){y=1;}
    cordX+=x;
    cordY+=y;
    }
}
